package com.yuantu.judiciary.dao;

import com.yuantu.judiciary.model.domain.VipInfoDO;
import com.yuantu.judiciary.model.enums.OrganizationType;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.sql.Timestamp;
import java.util.List;

/**
 * 套餐信息
 *
 * @author syw
 * @since 2023-08-11
 **/
public interface IVipInfoDao extends JpaRepository<VipInfoDO, Long> {

    VipInfoDO findByNameAndTypeAndDeletedFalse(String name, OrganizationType type);

    VipInfoDO findByIdAndDeletedFalse(Long id);

    VipInfoDO findByIdAndNameAndTypeAndDeletedFalse(Long id, String name, OrganizationType type);

    @Modifying
    @Query("update VipInfoDO set deleted = true, modifierId = :accountId, modifyTime = :currentTime " +
            "where ((coalesce (:id) is null and 1=0) or (coalesce (:id) is not null and id in (:id))) " +
            "and deleted = false ")
    void deleteByIdIn(List<Long> id, Long accountId, Timestamp currentTime);

    List<VipInfoDO> findByDeletedFalse();

    List<VipInfoDO> findByTypeAndDeletedFalse(OrganizationType type);
}
